﻿
using System;
using System.Security.Policy;

namespace Gola.VN.Scb.Web.Common.Entities
{
    public class ProductEntity : BaseEntity
    {
        public int Id { set; get; }

        public string Title { set; get; }

        public string Description { set; get; }

        public string ImageUrl { set; get; }

        public string BigImageUrl
        {
            get
            {
                return ("http://thegioisanpham.com.vn/Zip/ResizeImage?Path={0}&amp;width=486&amp;height=391");//Todo: Need create control to change ImageSize
            }
        }

        public string SmallImageUrl
        {
            get
            {
                return ("http://thegioisanpham.com.vn/Zip/ResizeImage?Path={0}&amp;width=125&amp;height=75");//Todo: Need create control to change ImageSize
            }
        }

        public string Link { set; get; }

        public double Price { set; get; }

        public double LastPrice { set; get; }

        public string Currency { set; get; }

        public string Promotion { set; get; }

        public string PromotionNonHtmltag
        {
            get
            {
                return string.IsNullOrWhiteSpace(Promotion)
                           ? string.Empty
                           : Promotion.RemoveHtmlTag();
            }
        }

        public int ViewCount { set; get; }

        public int ProviderId { set; get; }

        public string ProdiverName { set; get; }

        public string ProdiverAddress { set; get; }

        public int CategoryId { set; get; }

        public string CategoryName { set; get; }

        public string ProductId { set; get; }

        public string View
        {
            get
            {
                if (EnableGoToWebsite)
                {
                    return "#";
                }
                return string.Format(Constants.View.ProductDetail, Id, Title.ConvertToUnSign());
            }
        }


        public bool HasSaleOff
        {
            get { return Price > 0 && LastPrice < Price; }
        }

        public string SaleOffPercent
        {
            get
            {
                var saleOff = LastPrice - Price;
                bool hasSaleOff = (saleOff < LastPrice && Price > 0);
                if (hasSaleOff)
                {
                    return string.Format("{0}%", Math.Round((saleOff / Price) * 100).ToString());
                }
                return "0%";
            }
        }

        public string PriceDisplay
        {
            get
            {
                return
                    Price == 0 || Price == double.MinValue || Price == double.MaxValue ? string.Empty :
                    string.Format(Constants.PriceFormat, Price.ToString(Constants.DoubleFormatString), Currency);
            }
        }

        public string LastPriceDisplay
        {
            get
            {
                if (LastPrice == 0)
                {
                    return "Lien he cua hang";
                }
                return string.Format(Constants.PriceFormat, LastPrice.ToString(Constants.DoubleFormatString), Currency);
            }
        }

        public bool IsAlive { get; set; }

        public bool EnableGoToWebsite { set; get; }

        public ProviderEntity LocationDetail { get; set; }
    }
}
